home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7166 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: strange segementtation fault w/ fprintf
  5. Date: 15 Feb 96 00:00:36 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.824342436@rscernix>
  8. References: <312215BE.41C6@di.epfl.ch>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <312215BE.41C6@di.epfl.ch> Olivier Georg <ogeorg@di.epfl.ch> writes:
  13.  
  14. >value.  But when the first fprintf is reached, I get
  15. >a segmentation fault...  using GDB, I did a "where" where
  16. >the seg. fault occured, and here is the result:
  17. >
  18. >(gdb) where
  19. >#0  0xfabc814 in __malloc () at malloc.c:303
  20. >#1  0xfabf1e4 in _malloc () at malloc.c:484
  21. >#2  0xfac6830 in _findbuf () at _findbuf.c:96
  22. >#3  0xfabca38 in _doprnt () at doprnt.c:1588
  23. >#4  0xfac7ffc in fprintf () at fprintf.c:45
  24. >#5  0x402c04 in writevector (fp=0xfb52914, len=128, vect=0x100022f0) at
  25. >mlutil.c:99
  26. >#6  0x40256c in main () at online.c:219
  27.  
  28. fprintf is a red herring.  What you show here is a typical case
  29. of corrupted malloc arena.  You did bad things with pointers somewhere
  30. else in the code (probably wrote something in front or after a malloc'ed
  31. memory block) and corrupted your heap.  When fprintf tries to malloc
  32. a buffer for the 'fp' stream, the segmentation fault occurs.
  33.  
  34. If you can't find the bug in your code yourself, try to use a malloc
  35. debugging tool, e.g. ElectricFence which is free and available at many
  36. FTP servers (ask archie to find it).
  37.  
  38. Dan
  39. --
  40. Dan Pop
  41. CERN, CN Division
  42. Email: danpop@mail.cern.ch 
  43. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  44.